package com.wk.proto_android_demo;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import com.google.protobuf.InvalidProtocolBufferException;
import com.myProto.pack.Person;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            test();
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }



private void test() throws InvalidProtocolBufferException {
    Person person =  Person.newBuilder().
            setName("aivin666")
            .setIsMan(true)
            .setAge(20)
            .setMoney(1000)
            .setPhone("13650909087")
            .build();
    byte[] dataSend =  person.toByteArray();
    // 对象转byte[]
    WkLogTool.showLog(WkByteBitTools.byte2HexStr(dataSend));

    Person result  = Person.parseFrom(dataSend);
    //byte[]转对象
    WkLogTool.showLog( result.getName());
}
}
